#include <mach/mach_time.h>
height[100000],offset[100000];
long answer,temp;
main(i,n,value,j,tail)
{
	unsigned long long start = mach_absolute_time();
	for(;scanf("%d%d",&n,height)-1;printf("%ld\n",answer))
	{
		for(*offset=i=1,answer=0,tail=0;i++<n;)
		{
			scanf("%d",&value);

			if(height[tail]<value)
			{
				height[++tail]=value;
				offset[tail]=i;
			}
			else if(height[tail]>value)
			{
				while(~tail&&height[tail]>value)
				{
					temp=1L*height[tail]*(i-offset[tail]);
					answer=answer>temp?answer:temp;
					tail--;
				}
				height[++tail]=value;
/*				printf("@ : ");
				for(j=0;j<=tail;j++)
				{
					printf("%d ",height[j]);
				}
				puts("");
*/
				for(j=0;j<=tail;temp=1L*height[j]*(n-offset[j++]+1),answer=answer>temp?answer:temp);
			}

		}
	}

	printf("%lf\n",1e-9*(mach_absolute_time()-start));
}
